package com.sundaying.gooway.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;
import com.sundaying.gooway.entity.UrlItem;
import com.sundaying.gooway.service.UrlItemService;

public class UrlItemAction extends ActionSupport {
	private UrlItemService urlItemService;
	private List<UrlItem> urlItemList;
	private UrlItem urlItem;
	private long id;
	private String name;
	private int classId;

	// 将会被Struts2序列化为JSON字符串的对象
	private Map<String, Object> dataMap = new HashMap<String, Object>();
	// 视图datagrid属性
	private int page;
	private int rows;
	private long total;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getClassId() {
		return classId;
	}

	public void setClassId(int classId) {
		this.classId = classId;
	}

	public UrlItemService getUrlItemService() {
		return urlItemService;
	}

	@Resource(name = "urlItemService")
	public void setUrlItemService(UrlItemService urlItemService) {
		this.urlItemService = urlItemService;
	}

	public List<UrlItem> getUrlItemList() {
		return urlItemList;
	}

	public void setUrlItemList(List<UrlItem> urlItemList) {
		this.urlItemList = urlItemList;
	}

	public UrlItem getUrlItem() {
		return urlItem;
	}

	public void setUrlItem(UrlItem urlItem) {
		this.urlItem = urlItem;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}


	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public Map<String, Object> getDataMap() {
		return dataMap;
	}

	public void setDataMap(Map<String, Object> dataMap) {
		this.dataMap = dataMap;
	}

	public String add() {
		urlItemService.add(urlItem);
		return this.SUCCESS;
	}

	public String list() {
		urlItemList = urlItemService.list();
		return this.SUCCESS;
	}
	
	public String listByPage(){
		UrlItem urlItem = new UrlItem();
		urlItem.setClassId(classId);
		urlItem.setName(name);
		urlItemList = urlItemService.list(page, rows, "", "" ,urlItem);
		total = urlItemService.total(urlItem);
		dataMap.clear();
		dataMap.put("total", total);
		dataMap.put("rows", urlItemList);
		return this.SUCCESS;
	}

	public String update() {
		urlItemService.update(urlItem);
		return this.SUCCESS;
	}

	public String delete() {
		urlItemService.delete(id);
		return this.SUCCESS;
	}

}
